n = int(input())
List = list(range(1,n+1))
count = 0
while List:
    temp = List.pop(0)
    count += 1
    if (count % 7 == 0 or "7" in str(count)) and len(List) >= 1:
        continue
    List.append(temp)
    if len(List) == 1:
        for i in List:
            print(i)
        break
    '''csad'''